/*
 * @Description: ${codeGenConfig.genAuthor} SQL
 * @Author: DHL
 * @Date: 2022-01-30 14:20:12
 * @LastEditors: DHL
 * @LastEditTime: 2023-01-09 14:29:44
 */

import { firstToUpperCase, firstToLowerCase, getAuthKey } from '../../utils/codeGenUtils'

export function createSql(codeGenConfig: any) {
  const classNameFirstToLowerCase = firstToLowerCase(codeGenConfig.className)
  const resName = classNameFirstToLowerCase
    .replace(/([A-Z])/g, '_$1')
    .trim()
    .replaceAll('_', '-')
    .toUpperCase()

  let viewPath = codeGenConfig.viewPath.replace('views', '')
  if (viewPath.charAt(viewPath.length - 1) === '/') {
    viewPath = viewPath.substr(0, viewPath.length - 1)
  }

  return `
INSERT INTO twb_resource (ID, PARENT_RES_ID, NAME, URL, RES_TYPE, RES_SEQ, STATUS, ISLOG, PROJECT_ID, CREATOR, CREATE_DATE, ISDEL, VERSION) VALUES ('${resName}', '${
    codeGenConfig.resourceId ? codeGenConfig.resourceId : ''
  }', '${
    codeGenConfig.genName
  }', '${viewPath}/${classNameFirstToLowerCase}/index', '0', '1', '1', '1', '${
    codeGenConfig.projectId
  }',  '${codeGenConfig.genAuthor}', NOW(), '0', '2');
INSERT INTO twb_resource (ID, PARENT_RES_ID, NAME, URL, RES_TYPE, RES_SEQ, STATUS, ISLOG, PROJECT_ID, CREATOR, CREATE_DATE, ISDEL, VERSION) VALUES ('${getAuthKey(
    resName,
    'list'
  )}', '${resName}', '${codeGenConfig.genName!}列表', '', '1', '11', '1', '1', '${
    codeGenConfig.projectId
  }',  '${codeGenConfig.genAuthor}', NOW(), '0', '2');
INSERT INTO twb_resource (ID, PARENT_RES_ID, NAME, URL, RES_TYPE, RES_SEQ, STATUS, ISLOG, PROJECT_ID, CREATOR, CREATE_DATE, ISDEL, VERSION) VALUES ('${getAuthKey(
    resName,
    'add'
  )}', '${resName}', '${codeGenConfig.genName!}添加', '', '1', '12', '1', '1', '${
    codeGenConfig.projectId
  }',  '${codeGenConfig.genAuthor}', NOW(), '0', '2');
INSERT INTO twb_resource (ID, PARENT_RES_ID, NAME, URL, RES_TYPE, RES_SEQ, STATUS, ISLOG, PROJECT_ID, CREATOR, CREATE_DATE, ISDEL, VERSION) VALUES ('${getAuthKey(
    resName,
    'edit'
  )}', '${resName}', '${codeGenConfig.genName!}编辑', '', '1', '13', '1', '1', '${
    codeGenConfig.projectId
  }',  '${codeGenConfig.genAuthor}', NOW(), '0', '2');
INSERT INTO twb_resource (ID, PARENT_RES_ID, NAME, URL, RES_TYPE, RES_SEQ, STATUS, ISLOG, PROJECT_ID, CREATOR, CREATE_DATE, ISDEL, VERSION) VALUES ('${getAuthKey(
    resName,
    'view'
  )}', '${resName}', '${codeGenConfig.genName!}查看', '', '1', '14', '1', '1', '${
    codeGenConfig.projectId
  }',  '${codeGenConfig.genAuthor}', NOW(), '0', '2');
INSERT INTO twb_resource (ID, PARENT_RES_ID, NAME, URL, RES_TYPE, RES_SEQ, STATUS, ISLOG, PROJECT_ID, CREATOR, CREATE_DATE, ISDEL, VERSION) VALUES ('${getAuthKey(
    resName,
    'delBatch'
  )}', '${resName}', '${codeGenConfig.genName!}批量删除', '', '1', '16', '1', '1', '${
    codeGenConfig.projectId
  }',  '${codeGenConfig.genAuthor}', NOW(), '0', '2');
INSERT INTO twb_resource (ID, PARENT_RES_ID, NAME, URL, RES_TYPE, RES_SEQ, STATUS, ISLOG, PROJECT_ID, CREATOR, CREATE_DATE, ISDEL, VERSION) VALUES ('${getAuthKey(
    resName,
    'delLogicBatch'
  )}', '${resName}', '${codeGenConfig.genName!}批量逻辑删除', '', '1', '18', '1', '1', '${
    codeGenConfig.projectId
  }',  '${codeGenConfig.genAuthor}', NOW(), '0', '2');
INSERT INTO twb_resource (ID, PARENT_RES_ID, NAME, URL, RES_TYPE, RES_SEQ, STATUS, ISLOG, PROJECT_ID, CREATOR, CREATE_DATE, ISDEL, VERSION) VALUES ('${getAuthKey(
    resName,
    'exportExcel'
  )}', '${resName}', '${codeGenConfig.genName!}导出', '', '1', '19', '1', '1', '${
    codeGenConfig.projectId
  }',  '${codeGenConfig.genAuthor}', NOW(), '0', '2');
`
}
